/*
 * Copyright 2013 Agustina Martinez-Garcia

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
package uk.ljmu.metadata.staticschemas;

import java.io.InputStream;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.Resource;

public class StaticJenaDublinCore {
	 /** <p>The RDF model that holds the vocabulary terms</p> */
    private static Model m_model = ModelFactory.createDefaultModel();
    
    /** <p>The namespace of the vocabulary as a string</p> */
    public static final String NS = "http://purl.org/dc/elements/1.1/";
    
    /** <p>The namespace of the vocabulary as a string</p>
     *  @see #NS */
    public static String getURI() {return NS;}
    
    /** <p>The namespace of the vocabulary as a resource</p> */
    public static final Resource NAMESPACE = m_model.createResource( NS );
    
    /** <p>An entity responsible for making contributions to the resource.</p> */
    public static final Property contributor = m_model.createProperty( "http://purl.org/dc/elements/1.1/contributor" );
    
    /** <p>The spatial or temporal topic of the resource, the spatial applicability of 
     *  the resource, or the jurisdiction under which the resource is relevant.</p>
     */
    public static final Property coverage = m_model.createProperty( "http://purl.org/dc/elements/1.1/coverage" );
    
    /** <p>An entity primarily responsible for making the resource.</p> */
    public static final Property creator = m_model.createProperty( "http://purl.org/dc/elements/1.1/creator" );
    
    /** <p>A point or period of time associated with an event in the lifecycle of the 
     *  resource.</p>
     */
    public static final Property date = m_model.createProperty( "http://purl.org/dc/elements/1.1/date" );
    
    /** <p>An account of the resource.</p> */
    public static final Property description = m_model.createProperty( "http://purl.org/dc/elements/1.1/description" );
    
    /** <p>The file format, physical medium, or dimensions of the resource.</p> */
    public static final Property format = m_model.createProperty( "http://purl.org/dc/elements/1.1/format" );
    
    /** <p>An unambiguous reference to the resource within a given context.</p> */
    public static final Property identifier = m_model.createProperty( "http://purl.org/dc/elements/1.1/identifier" );
    
    /** <p>A language of the resource.</p> */
    public static final Property language = m_model.createProperty( "http://purl.org/dc/elements/1.1/language" );
    
    /** <p>An entity responsible for making the resource available.</p> */
    public static final Property publisher = m_model.createProperty( "http://purl.org/dc/elements/1.1/publisher" );
    
    /** <p>A related resource.</p> */
    public static final Property relation = m_model.createProperty( "http://purl.org/dc/elements/1.1/relation" );
    
    /** <p>Information about rights held in and over the resource.</p> */
    public static final Property rights = m_model.createProperty( "http://purl.org/dc/elements/1.1/rights" );
    
    /** <p>A related resource from which the described resource is derived.</p> */
    public static final Property source = m_model.createProperty( "http://purl.org/dc/elements/1.1/source" );
    
    /** <p>The topic of the resource.</p> */
    public static final Property subject = m_model.createProperty( "http://purl.org/dc/elements/1.1/subject" );
    
    /** <p>A name given to the resource.</p> */
    public static final Property title = m_model.createProperty( "http://purl.org/dc/elements/1.1/title" );
    
    /** <p>The nature or genre of the resource.</p> */
    public static final Property type = m_model.createProperty( "http://purl.org/dc/elements/1.1/type" );
    
    public static Model getModel()
    {
	ClassLoader classLoader = Thread.currentThread()
	.getContextClassLoader();
	InputStream is;
	is = classLoader.getResourceAsStream("dc.rdf");

    	Model myModel = ModelFactory.createDefaultModel();
    	
    	try {
    	    myModel.read(is, "");
    	    return myModel;
    	}catch (Exception ex) {
    	    return myModel;
    	}      
    }
    
    public static boolean containsProperty(String localName)
    {
    	if (StaticJenaDublinCore.contributor.getLocalName().equals(localName) ||
    			StaticJenaDublinCore.coverage.getLocalName().equals(localName) ||
    			StaticJenaDublinCore.creator.getLocalName().equals(localName) ||
    			StaticJenaDublinCore.date.getLocalName().equals(localName) ||
    			StaticJenaDublinCore.description.getLocalName().equals(localName) ||
    			StaticJenaDublinCore.format.getLocalName().equals(localName) ||
    			StaticJenaDublinCore.identifier.getLocalName().equals(localName) ||
    			StaticJenaDublinCore.language.getLocalName().equals(localName) ||
    			StaticJenaDublinCore.publisher.getLocalName().equals(localName) ||
    			StaticJenaDublinCore.relation.getLocalName().equals(localName) ||
    			StaticJenaDublinCore.rights.getLocalName().equals(localName) ||
    			StaticJenaDublinCore.source.getLocalName().equals(localName) ||
    			StaticJenaDublinCore.subject.getLocalName().equals(localName) ||
    			StaticJenaDublinCore.type.getLocalName().equals(localName) ||
    			StaticJenaDublinCore.title.getLocalName().equals(localName))
    		return true;
    	else return false;
    }
}
